package com.HomeWorkhsp.chapter10.homework.homework06;


/**
 * Enjoy programming!!!
 * Time: 2021/12/12 -  18:46
 */
public class Horse implements Vehicles {
    @Override
    public void work(){
        System.out.println("一般情况之下，使用马儿前进");
    }
}
class Boat implements Vehicles{
    @Override
    public void work(){
        System.out.println("使用小船过河");
    }
}

class Person{

     private final String name;
     private Vehicles vehicles;


    public Person(String name, Vehicles vehicles) {
//        vehicles.work();
        this.name = name;
        this.vehicles = vehicles;
    }
    public void crossRiver(){
        if(!(vehicles instanceof Boat)){
            vehicles = new VehiclesFactory().getBoat();
        }
        vehicles.work();

    }
    public void common(){
        if(!(vehicles instanceof Horse)){
            vehicles = new VehiclesFactory().getHorse();
        }
        vehicles.work();
    }

    public String getName() {
        return name;
    }

    public Vehicles getVehicles() {
        return vehicles;
    }

}